<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="js/jquery-3.5.1.js"></script>
</head>
<body>
<div>前后端交互</div>
<script type="text/javascript">
    /*
        前后端交互-异步编程与promise概述
     */
    // console.dir(Promise)
    // fetch('http://localhost:3000/data').then(function(data){
    //     return data.text();
    // }).then(function(data){
    //     console.log(data)
    // })
    // fetch('http://localhost:3000/books/789',{
    //     method:'delete'
    // })
    // .then(function (data) {
    //     return data.text();
    // }).then(function(data){
    //     console.log(data)
    // })

    fetch('http://localhost:3000/books',{
        method:'post',
        body:'uname=lisi&pwd=123',
        headers:{
            'Content-Type':'application/x-www-form-urlencoded'
        }
    })
    .then(function(data){
        return data.text();
    }).then(function(data){
        console.log(data)
    })
</script>
</body>
</html>